package teamproject.visualization.gui;

import java.util.ArrayList;

import teamproject.visualization.gui.visualobjects.Belt;
import teamproject.visualization.gui.visualobjects.Package;
import teamproject.visualization.gui.visualobjects.TransparentBuffer;
import teamproject.visualization.gui.visualobjects.TransparentEdge;

public class VisualObjectContainer {

	private static VisualObjectContainer instance = new VisualObjectContainer();

	public static VisualObjectContainer getInstance() {
		return instance;
	}
	private boolean densityVisible = false;

	private boolean packagesVisible = true;
	private ArrayList<TransparentBuffer> buffers = new ArrayList<TransparentBuffer>();
	private ArrayList<TransparentEdge> edges = new ArrayList<TransparentEdge>();
	private ArrayList<Belt> belts = new ArrayList<Belt>();

	private ArrayList<Package> packets = new ArrayList<Package>();

	private VisualObjectContainer() {
	}

	public void add(Belt belt) {
		belts.add(belt);
	}

	public void add(Package packet) {
		packets.add(packet);
	}

	public void add(TransparentBuffer buffer) {
		buffers.add(buffer);
	}

	public void add(TransparentEdge edge) {
		edges.add(edge);
	}

	public boolean isDensityVisible() {
		return densityVisible;
	}

	public boolean isPackageVisible() {
		return packagesVisible;
	}

	public void setDensityVisible(boolean visible) {
		for (TransparentBuffer buffer : buffers) {
			buffer.setVisible(visible);
		}

		for (TransparentEdge edge : edges) {
			edge.setVisible(visible);
		}

		densityVisible = visible;
	}

	public void setPackageVisible(boolean visible) {
		for (Package packet : packets) {
			if (packet.isAnimatedVisible() && visible)
				packet.setVisible(visible);
			else if (!packet.isAnimatedVisible() && visible)
				packet.setVisible(false);
			else if (packet.isAnimatedVisible() && !visible)
				packet.setVisible(visible);
			else if (!packet.isAnimatedVisible() && !visible)
				packet.setVisible(visible);
		}

		for (Belt belt : belts) {
			belt.setVisible(visible);
		}

		packagesVisible = visible;
	}
}
